//
//  STChannelHeaderView.swift
//  StarTimesON
//
//  Created by Toj on 9/26/22.
//  Copyright © 2022 StarTimes. All rights reserved.
//

import UIKit

class STChannelHeaderView: UICollectionReusableView {
    
    var section: STCommodityMobileSectionModel? { didSet {
        titleLabel.text = section?.title
        let channelsCount = section?.commodityChannel?.showChannels.count ?? 0
        imageView.isHidden = channelsCount == 0
    } }
    
    var tvSection: STCommodityTVSectionModel? { didSet {
        titleLabel.text = tvSection?.title
        let channelsCount = tvSection?.channelCellModel?.showChannels.count
        imageView.isHidden = channelsCount == 0
    } }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        addSubview(imageView)
        imageView.addSubview(titleLabel)
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        imageView.snp.makeConstraints { make in
            make.left.right.equalTo(self).inset(18)
            make.bottom.equalTo(self)
            make.height.equalTo(32.ui_scale)
        }
        titleLabel.snp.makeConstraints { make in
            make.left.right.equalTo(imageView).inset(12.ui_scale)
            make.centerY.equalTo(imageView)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private lazy var imageView: UIImageView = {
        let view = UIImageView()
        view.image = "commodity_channel_header_bg".to_image
        return view
    }()
    
    private lazy var titleLabel: UILabel = {
        let view = UILabel()
        view.font = UIFont.boldSystemFont(ofSize: 12.f_scale)
        view.textColor = "#99773C".to_color
        return view
    }()
}
